${prepare}

uniform float speed;
uniform ece_LightSource light[MaxLightCount];
uniform ece_Fog fog;
uniform ece_Material material;
uniform vec4 global_Ambient;
uniform vec3 cameraPosition;
attribute vec4 ece_Vertex;
attribute vec2 ece_TexCoord;
varying vec2 vTexCoord;
varying vec3 vPosition;
varying float vDistance;
varying vec3 vTangentViewPos;
varying vec3 vTangentFragPos;
void main() {
	gl_Position = ece_ModelViewProjectionMatrix * ece_Vertex;
	vPosition = vec3(ece_ModelViewMatrix * ece_Vertex);
	vDistance = length(gl_Position.xyz);
	
	vec3 tangent = vec3(0, 0, 1.0); 
    vec3 binormal = vec3(1.0, 0, 0); 
	vec3 normal = vec3(0, 1.0, 0);
	
    vec3 T = normalize(ece_NormalMatrix * tangent);
    vec3 B = normalize(ece_NormalMatrix * binormal);
    vec3 N = normalize(ece_NormalMatrix * normal);
    
    // 构造出 TBN 矩阵
    mat3 TBN = transpose(mat3(T, B, N));
    
	vTangentViewPos = cameraPosition * TBN;
	vTangentFragPos = vPosition * TBN;
	vTexCoord = ece_TexCoord;
}